<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增章节管理')" />
    <style>
        .file-preview{
            height: 500px !important;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-management-add">
            <h4 class="form-header h4">章节管理信息</h4>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">课程ID：</label>
                <div class="col-sm-8">
                    <input name="courseId" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">章节名称：</label>
                <div class="col-sm-8">
                    <input name="sectionName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">章节序列：</label>
                <div class="col-sm-8">
                    <select name="sectionSequence" class="form-control m-b" th:with="type=${@dict.getType('chapter_sort')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">章节备注：</label>
                <div class="col-sm-8">
                    <textarea name="sectionRemark" class="form-control"></textarea>
                </div>
            </div>
           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">乐观锁：</label>
                <div class="col-sm-8">
                    <input name="revision" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">逻辑删除：</label>
                <div class="col-sm-8">
                    <input name="deleted" class="form-control" type="text">
                </div>
            </div>-->
           <!-- <h4 class="form-header h4">子章节信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "course/management"
        var isWatchDatas = [[${@dict.getType('sys_yes_no')}]];
        var sonSequenceDatas = [[${@dict.getType('chapter_sort')}]];
        var createByDatas = [[${@dict.getType('system_role')}]];
        var updateByDatas = [[${@dict.getType('system_role')}]];
        $("#form-management-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-management-add').serialize());
            }
        }

        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'sonSectionName',
                    align: 'center',
                    title: '子章节名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].sonSectionName' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'sonSectionVideo',
                    align: 'center',
                    title: '子章节视频',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].sonSectionVideo' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'isWatch',
                    align: 'center',
                    title: '是否允许观看',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("sonSectionList[%s].isWatch", index);
                        return $.common.dictToSelect(isWatchDatas, value, name);
                    }
                },
                {
                    field: 'sonSequence',
                    align: 'center',
                    title: '子章节序列',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("sonSectionList[%s].sonSequence", index);
                        return $.common.dictToSelect(sonSequenceDatas, value, name);
                    }
                },
                {
                    field: 'sonSectionRemark',
                    align: 'center',
                    title: '子章节备注',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].sonSectionRemark' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'revision',
                    align: 'center',
                    title: '乐观锁',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].revision' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'createBy',
                    align: 'center',
                    title: '创建人',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].createBy' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'updateBy',
                    align: 'center',
                    title: '更新人',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].updateBy' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'updateTime',
                    align: 'center',
                    title: '更新时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].updateTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'deleted',
                    align: 'center',
                    title: '逻辑删除',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sonSectionList[%s].deleted' value='%s'>", index, value);
                        return html;
                    }
                
                }]
            };
            $.table.init(options);
        });

        function addColumn() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            sub.editColumn();
        	
            $("#" + table.options.id).bootstrapTable('insertRow', {
                index: count,
                row: {
                    index: $.table.serialNumber(count),
                    sonSectionName: "",
                    sonSectionVideo: "",
                    isWatch: "",
                    sonSequence: "",
                    sonSectionRemark: "",
                    revision: "",
                    createBy: "",
                    createTime: "",
                    updateBy: "",
                    updateTime: "",
                    deleted: ""
                }
            });
        }
    </script>
</body>
</html>